#include <iostream>
#include <stdlib.h>
#include "ArrayListUtil.hpp"
#include "ArrayList.hpp"
#include "Sorters/SelectSorter.hpp"
#include "RandomDataGenerator.hpp"
#include "AscendingDataGenerator.hpp"
#include "HeapSorter.hpp"

using namespace std;

void printVector( OwnCollections::ArrayList<int>& vector) {
    int size = vector.getCount();
    for( int i = 0; i < size; i++ ) {
        cout << "vector[" << i << "] = " << vector.get(i) << endl;
    }
}

void printUsage( const char *programName ) {
    cout << "Usage: " << programName << " collectionSize " << endl;
}

int main(int argc, char** argv) {
    if( argc < 2 ) {
        printUsage(argv[0]);
        return 0;
    }

    int vectorSize = atoi( argv[1] );
    if( vectorSize <= 0 ) {
        cout << "collectionSize must be more then 0" << endl;
        return 0;
    }

    OwnCollections::ArrayList<int> vector;
    
    DataGenerator *dataGenerator = new AscendingDataGenerator();
    //DataGenerator *dataGenerator = new RandomDataGenerator();
    Sorter *sorter = new HeapSorter();
    
    dataGenerator->generateData(vector, vectorSize);
    sorter->sort(vector);
    
    delete dataGenerator;
    delete sorter;

    printVector(vector);
    if( ArrayListUtil::checkThatElementsAreInAscendingOrder(vector) ) {
        cout << "sorting is correct" << endl;
    } else {
        cout << "Sorting is incorrect" << endl;
    }
    
    return 0;
}

